<template>
  <div id="popupp" class="ol-popupp" v-show="isPopup">
    <span>事件详情</span>
    <a href="#" id="popupp-closer" class="ol-popupp-closer"></a>
    <div id="popupp-content">
      <table border="1" cellspacing="0" style="table-layout: fixed">
        <tr>
          <td>事件等级</td>
          <td>{{ eventlevel }}</td>
        </tr>
        <tr>
          <td>发生时间</td>
          <td>{{ eventtime }}</td>
        </tr>
        <tr>
          <td>发生地点</td>
          <td>{{ eventlocation }}</td>
        </tr>
        <tr>
          <td>处理状态</td>
          <td>{{ eventstatus }}</td>
        </tr>
        <tr v-show="isserect">
          <td>车牌号</td>
          <td>{{ carnumber }}</td>
        </tr>
        <tr v-show="isserect">
          <td>驾驶员</td>
          <td>{{ driver }}</td>
        </tr>
      </table>
    </div>
  </div>
</template>

<script setup>
import mitt from '@/mitt'
import { ref, onUnmounted, computed } from 'vue'
import { useStore } from 'vuex'
import Search from '../Hooks/Search'
const { onSearch, unSearch } = Search()
const { map } = defineProps({
  map: {
    type: Object,
  },
})

const $store = useStore()
const userinformation = computed(() => $store.state.userinformation)
const user_type = userinformation.value.user_type
const isPopup = ref(false)
const isserect = ref(false)
const eventlevel = ref('')
const eventtime = ref('')
const eventlocation = ref('')
const eventstatus = ref('')
const carnumber = ref('')
const driver = ref('')

const onSearchs = (event) => {
  isPopup.value = true
  if (user_type == 'admin' || user_type == 'traffic') {
    isserect.value = true
  }
  onSearch(
    map,
    event,
    eventlevel,
    eventtime,
    eventlocation,
    eventstatus,
    carnumber,
    driver
  )
}

const unSearchs = () => {
  isPopup.value = false

  unSearch(map)
}
// 事件监听与解绑
mitt.on('onSearch', onSearchs)
mitt.on('unSearch', unSearchs)
onUnmounted(() => {
  mitt.off('onSearch', onSearchs)
})
</script>

<style scoped>
.ol-popupp {
  position: absolute;
  background-color: white;
  -webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  width: 250px;
  padding: 15px;
  border-radius: 10px;
  border: 1px solid #cccccc;
  bottom: 45px;
  left: -50px;
}

.ol-popupp:after,
.ol-popupp:before {
  top: 100%;
  border: solid transparent;
  content: ' ';
  height: 0;
  width: 0;
  position: absolute;
  pointer-events: none;
}

.ol-popupp:after {
  border-top-color: white;
  border-width: 10px;
  left: 48px;
  margin-left: -10px;
}

.ol-popupp:before {
  border-top-color: #cccccc;
  border-width: 11px;
  left: 48px;
  margin-left: -11px;
}

.ol-popupp-closer {
  text-decoration: none;
  position: absolute;
  top: 2px;
  right: 8px;
}

.ol-popupp-closer:after {
  content: '×';
}

#popupp-content {
  font-size: 14px;
  font-family: '微软雅黑';
}

#popupp-content img {
  width: 30px;
}
span {
  color: cadetblue;
}
table {
  margin-top: 10px;
}
td:first-child {
  width: 80px;
  font-weight: 800;
}
td:last-child {
  width: 170px;
}
</style>
